<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div>
            <header style="height: 100%">
                <div align="left">
                    <table style="width: 100%">
                        <tr>
                            <td>
                                <form class="form-inline" onsubmit="return false">
                                    <div class="form-group">
                                        发送人id：
                                        <input id="sendId" type="text" class="form-control" placeholder="sendId">
                                        接收人id：
                                        <input id="receiveId" type="text" class="form-control" placeholder="receiveId">
                                        <button id="searchBt" class="layui-btn layui-btn-sm"
                                                permission="sys:mfflTypes:query"><i class="layui-icon">&#xe615;</i>搜索
                                        </button>
                                    </div>
                                </form>
                            </td>
                            <!--<td align="right">-->
                            <!--<button class="layui-btn layui-btn-sm" onclick="location.href='addMfflChatContent.html'">-->
                            <!--<i class="layui-icon">&#xe608;</i> 添加-->
                            <!--</button>-->
                            <!--</td>-->
                        </tr>
                    </table>
                </div>
            </header>

            <div>
                <div class="widget-body no-padding">
                    <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                        <thead>
                        <tr>
                        </tr>
                        <tr>
                            <th>id</th>
                            <th>发送人id</th>
                            <th>接收人id</th>
                            <th>聊天内容</th>
                            <th>内容状态</th>
                            <th>发送时间</th>
                            <th>聊天关系id</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
    var pers = checkPermission();

    var example;

    function init() {
        example =
            $('#dt-table').on('preXhr.dt', function (e, settings, data) {
                var columns = data.columns;
                for (var i = 0; i < columns.length; i++) {
                    if (columns[i].name) {
                        data.columns[i].data = columns[i].name;
                    }
                }
            }).DataTable({
                "searching": false,
                "processing": false,
                "serverSide": true,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/mfflChatContents",
                    "type": "get",
                    "data": function (d) {
                        d.sendId = $("#sendId").val();
                        d.receiveId = $("#receiveId").val();
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {"data": "id", "defaultContent": ""},
                    {"data": "sendId", "defaultContent": "", "name": "send_id"},
                    {"data": "receiveId", "defaultContent": "", "name": "receive_id"},
                    {"data": "content", "defaultContent": ""},
                    {
                        "data": "status",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            var flag = row['status'];
                            if (flag == "1") {
                                return "未读";
                            } else {
                                return "已读";
                            }
                        }
                    },
                    {"data": "createTime", "defaultContent": ""},
                    {"data": "mappingId", "defaultContent": "", "name": "mapping_id"},
                    {
                        "data": "",
                        "defaultContent": "",
                        "orderable": false,
                        "render": function (data, type, row) {
                            var id = row['id'];
                            var href = "updateMfflChatContent.html?id=" + id;
                            // var edit = buttonEdit(href, "sys:chatContents:add", pers);
                            var del = buttonDel(id, "sys:chatContents:del", pers);
                            return del;
                        }
                    },

                ],
                "order": [[0, "asc"]],
                columnDefs: [
                    {
                        "orderable": false,
                        "targets": [1, 2, 3, 4, 6]  // 哪些列不排序
                    }
                ],
            });
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });

    function del(id) {
        layer.confirm('确定要删除吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.ajax({
                type: 'delete',
                url: '/mfflChatContents/' + id,
                success: function (data) {
                    example.ajax.reload();
                    layer.msg("删除成功");
                }
            });

            layer.close(1);
        });
    }

    $("#searchBt").click(function () {
        example.ajax.reload();
    });

    init();
</script>
